package com.itheima;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.dao.UserDao;
import com.itheima.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

@SpringBootTest
public class MpBeach {
    @Autowired
    private UserDao userDao;

    @Test
    void test1() {
        //批量删除
        List<Long> list = new ArrayList<>();
        list.add(8l);
        list.add(7l);
        int i = userDao.deleteBatchIds(list);
        System.out.println("影响的条数" + i);
    }

    @Test
    void test2() {
        //批量查询
        List<Long> list = new ArrayList<>();
        list.add(8l);
        list.add(7l);
        List<User> users = userDao.selectBatchIds(list);
        System.out.println(users);
    }

    @Test
        //批量查询2
    void test3() {
        //批量查询
        List<Long> list = new ArrayList<>();
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.in("id", list);
        List<User> users = userDao.selectList(userQueryWrapper);
        System.out.println(users);
    }

    //分组查询
    @Test
    void fenzu() {
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        //投影
        userQueryWrapper.select("password", "count(*) as count");
        //分组
        userQueryWrapper.groupBy("password");

        List<Map<String, Object>> maps = userDao.selectMaps(userQueryWrapper);
        for (Map<String, Object> map : maps) {
            Set<Map.Entry<String, Object>> entries = map.entrySet();
            for (Map.Entry<String, Object> entry : entries) {
                String key = entry.getKey();
                Object value = entry.getValue();
                System.out.println(key + value);
            }
        }
    }

}
